package com.exmaple.springcloud.controller;

import cn.hutool.core.util.IdUtil;
import com.exmaple.springcloud.domain.R;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/pay")
public class PaySentinelController {

    //Sentinel 限流的示例
    @GetMapping(value = "/sentinel/fc/{id}")
    public R<String> sentinelFC(@PathVariable("id") Integer id)
    {

        return  R.ok("Hello, sentinel! inputId:  "+id+" \t " + IdUtil.simpleUUID(),"成功");//模拟正常情况
    }



    //Sentinel 熔断的示例
    @GetMapping(value = "/sentinel/circuit/{id}")
    public R<String> sentinelCircuit(@PathVariable("id") Integer id)
    {
        if(id == -4) throw new RuntimeException("----sentinel id 不能负数"); //模拟报错情况
        if(id == 9999){//模拟超时情况
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        return  R.ok("Hello, sentinel! inputId:  "+id+" \t " + IdUtil.simpleUUID(),"成功");//模拟正常情况
    }
}